This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
library(tidyverse)
package ‘tidyverse’ was built under R version 3.4.2── Attaching packages ──────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 2.2.1 ✔ purrr 0.2.4
✔ tibble 1.4.2 ✔ dplyr 0.7.4
✔ tidyr 0.8.0 ✔ stringr 1.3.0
✔ readr 1.1.1 ✔ forcats 0.3.0
package ‘tibble’ was built under R version 3.4.3package ‘tidyr’ was built under R version 3.4.3package ‘purrr’ was built under R version 3.4.2package ‘dplyr’ was built under R version 3.4.2── Conflicts ─────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
df <- read_csv('data.csv')
Parsed with column specification:
cols(
ICD.Chapter = col_character(),
State = col_character(),
Year = col_integer(),
Deaths = col_integer(),
Population = col_integer(),
Crude.Rate = col_double()
)
df1 <- df %>%
dplyr::filter(ICD.Chapter == 'Neoplasms' & Year == 2010)
p <- plot_ly(
x = df1$State,
y = df1$Deaths,
name = "Deaths 2010",
type = "bar"
)
p
library(plotly)
p <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")
p
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).
p <- ggplot(data = df1, aes(x = State, y = Deaths)) +
geom_bar(stat = 'identity')
p
# ggplotly(p) %>%
# layout(height = input$plotHeight, autosize=TRUE)
df <- read_csv('/Users/kailukowiak/DATA_608/Assignment3/data.csv')
Parsed with column specification:
cols(
ICD.Chapter = col_character(),
State = col_character(),
Year = col_integer(),
Deaths = col_integer(),
Population = col_integer(),
Crude.Rate = col_double()
)
CoDChoice <- unique(df$ICD.Chapter)
yearChoice <- unique(df$Year)
outputVar <- c('Deaths', 'Population', 'Crude.Rate')
stockGraph <- function(){
df1 <- df %>% dplyr::filter(Year == 2010 & ICD.Chapter == 'Neoplasms')
p <- ggplot(df1, aes(x = State, y = Deaths)) +
geom_bar(stat = 'identity')
p
# grid.arrange(p, ncol=1)
}
stockGraph()
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
lakecolor = toRGB('white')
)
p1 <- plot_ly(z = state.area, text = state.name, locations = state.abb,
type = 'choropleth', locationmode = 'USA-states') %>%
layout(geo = g)
stockGraph <- function(df, CoD, year){
df <- read_csv('/Users/kailukowiak/DATA_608/Assignment3/data.csv')
df <- df[df$Year == year,]
df <- df[df$ICD.Chapter == CoD,]
#%>% dplyr::filter(Year == year & ICD.Chapter == CoD)
# p <- ggplot(data = df, aes(x = State, y = Crude.Rate)) +
# geom_bar(stat = 'identity') +
# theme_tufte()
# #ggplotly(p)
# grid.arrange(p, ncol=1)
p1 <- plot_ly(
x = df$State,
y = df$Crude.Rate,
name = "Death Rate",
type = "bar"
)
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
lakecolor = toRGB('white')
)
p2 <- plot_ly(z = state.area, text = state.name, locations = state.abb,
type = 'choropleth', locationmode = 'USA-states') %>%
layout(geo = g)
p <- subplot(p1, p2, nrows = 2) %>%
layout(title = "Deaths by Various Diseases",
showlegend=FALSE,showlegend2=FALSE)
#p
p
}
stockGraph(df, "Neoplasms", 2010)
Parsed with column specification:
cols(
ICD.Chapter = col_character(),
State = col_character(),
Year = col_integer(),
Deaths = col_integer(),
Population = col_integer(),
Crude.Rate = col_double()
)
Can't display both discrete & non-discrete data on same axisCan't display both discrete & non-discrete data on same axis
pTest <- plot_ly(
x = df$State,
y = df$Crude.Rate,
name = "Death Rate",
type = "bar")
pTest
df <- read_csv('Problem1/data.csv')
Parsed with column specification:
cols(
ICD.Chapter = col_character(),
State = col_character(),
Year = col_integer(),
Deaths = col_integer(),
Population = col_integer(),
Crude.Rate = col_double()
)
df <- df %>%
dplyr::filter(Year == 2010 & ICD.Chapter == 'Neoplasms') %>%
dplyr::arrange(desc(Crude.Rate))
xform <- list(categoryorder = "array",
categoryarray = df$State)
p1 <- plot_ly(
x = df$State,
y = df$Crude.Rate,
name = "Death Rate",
type = "bar") %>%
layout(xaxis = xform)
p1 %>% add_trace(x = seq(0, 250, 50),#c(0.4, 9.6, NA, 0.4, 9.6, NA, 0.4, 9.6, NA, 0.4, 9.6, NA, 0.4, 9.6),
y =seq(0, 250, 50), mode = "lines",
marker = list(color = "white"), showlegend = F) %>%
layout(annotations = list(
list(x = 1, xanchor = "left", y = 250, showarrow = F, ax = 0, ay = 0, align = "left",
text = "Average scores<br>on negative emotion traits<br>from 3896 participants<br>(Watson et al., 1988)")))
Can't display both discrete & non-discrete data on same axis'bar' objects don't have these attributes: 'mode'
Valid attributes include:
'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'hoverinfo', 'hoverlabel', 'stream', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'orientation', 'base', 'offset', 'width', 'marker', 'r', 't', 'error_y', 'error_x', '_deprecated', 'xaxis', 'yaxis', 'xcalendar', 'ycalendar', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule'
Can't display both discrete & non-discrete data on same axis'bar' objects don't have these attributes: 'mode'
Valid attributes include:
'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'hoverinfo', 'hoverlabel', 'stream', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'textposition', 'textfont', 'insidetextfont', 'outsidetextfont', 'orientation', 'base', 'offset', 'width', 'marker', 'r', 't', 'error_y', 'error_x', '_deprecated', 'xaxis', 'yaxis', 'xcalendar', 'ycalendar', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule'
library(psych)
library(reshape2)
ds <- melt(colMeans(msq[,c(2,7,34,36,42,43,46,55,68)],na.rm = T)*10)
ds$trait <- rownames(ds)
hovertxt <- paste(ds$trait, ":", round(ds$value,3))
plot_ly(ds, x = 1:nrow(ds), y = df$value, type = "bar", marker = list(color = "#737373"),
hoverinfo = "text", showlegend = F, text = hovertxt) %>%
add_trace(x = c(0.4, 9.6, NA, 0.4, 9.6, NA, 0.4, 9.6, NA, 0.4, 9.6, NA, 0.4, 9.6),
y = c(1, 1, NA, 2, 2, NA, 3, 3, NA, 4, 4, 5, 5), mode = "lines",
marker = list(color = "white"), showlegend = F) %>%
layout(xaxis = list(title = "", tickmode = "array", tickvals = 1:nrow(ds), ticktext = ds$trait,
tickfont = list(family = "serif", size = 10)),
yaxis = list(title = "", showgrid = F),
annotations = list(
list(x = 1, xanchor = "left", y = 6, showarrow = F, ax = 0, ay = 0, align = "left",
text = "Average scores<br>on negative emotion traits<br>from 3896 participants<br>(Watson et al., 1988)")))
Unknown or uninitialised column: 'value'.Error: Columns `y`, `text` must be length 1 or 14, not 13, 9